package com.ruoyi.waybill.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.annotation.DataCustom;
import com.ruoyi.common.constant.WaybillConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.waybill.mapper.TWayBillInfoMapper;
import com.ruoyi.waybill.domain.TWayBillInfo;
import com.ruoyi.waybill.service.ITWayBillInfoService;

/**
 * 运单信息Service业务层处理
 * 
 * @author wzy
 * @date 2024-12-31 19:09:03
 */
@Service
public class TWayBillInfoServiceImpl implements ITWayBillInfoService 
{
    @Autowired
    private TWayBillInfoMapper tWayBillInfoMapper;

    /**
     * 查询运单信息
     * 
     * @param wayBillId 运单信息主键
     * @return 运单信息
     */
    @Override
    public TWayBillInfo selectTWayBillInfoByWayBillId(Long wayBillId)
    {
        return tWayBillInfoMapper.selectTWayBillInfoByWayBillId(wayBillId);
    }

    /**
     * 查询运单信息列表
     * 
     * @param tWayBillInfo 运单信息
     * @return 运单信息
     */
    @Override
    @DataCustom(customAlias = "c", userAlias = "u")
    public List<TWayBillInfo> selectTWayBillInfoList(TWayBillInfo tWayBillInfo)
    {
        return tWayBillInfoMapper.selectTWayBillInfoList(tWayBillInfo);
    }

    /**
     * 新增运单信息
     * 
     * @param tWayBillInfo 运单信息
     * @return 结果
     */
    @Override
    public int insertTWayBillInfo(TWayBillInfo tWayBillInfo)
    {
        tWayBillInfo.setCreateTime(DateUtils.getNowDate());
        return tWayBillInfoMapper.insertTWayBillInfo(tWayBillInfo);
    }

    /**
     * 修改运单信息
     * 
     * @param tWayBillInfo 运单信息
     * @return 结果
     */
    @Override
    public int updateTWayBillInfo(TWayBillInfo tWayBillInfo)
    {
        tWayBillInfo.setUpdateTime(DateUtils.getNowDate());
        return tWayBillInfoMapper.updateTWayBillInfo(tWayBillInfo);
    }

    /**
     * 批量删除运单信息
     * 
     * @param wayBillIds 需要删除的运单信息主键
     * @return 结果
     */
    @Override
    public int deleteTWayBillInfoByWayBillIds(Long[] wayBillIds)
    {
        return tWayBillInfoMapper.deleteTWayBillInfoByWayBillIds(wayBillIds);
    }

    /**
     * 删除运单信息信息
     * 
     * @param wayBillId 运单信息主键
     * @return 结果
     */
    @Override
    public int deleteTWayBillInfoByWayBillId(Long wayBillId)
    {
        return tWayBillInfoMapper.deleteTWayBillInfoByWayBillId(wayBillId);
    }

    /**
     * 查询运单信息
     *
     * @param waybillNumber 运单信息主键
     * @return 运单信息
     */
    @Override
    public TWayBillInfo selectTWayBillInfoByWayBillNumber(String waybillNumber)
    {
        return tWayBillInfoMapper.selectTWayBillInfoByWayBillNumber(waybillNumber);
    }

    /**
     * 修改运单信息
     *
     * @param tWayBillInfo 运单信息
     * @return 结果
     */
    @Override
    public int updateTWayBillInfoByWayBillNumber(TWayBillInfo tWayBillInfo)
    {
        return tWayBillInfoMapper.updateTWayBillInfoByWayBillNumber(tWayBillInfo);
    }

    /**
     * 车牌号码列表
     *
     * @param vehicleMark 车辆标记
     * @param beginDate 开始日期
     * @param endDate 结束日期
     * @return 结果
     */
    @Override
    public List<String> selectProfitStatisticFieldByRecordDate(String vehicleMark, Date beginDate, Date endDate)
    {
        return tWayBillInfoMapper.selectProfitStatisticFieldByRecordDate(vehicleMark, beginDate, endDate);
    }

    /**
     * 查询运单信息列表
     *
     * @param vehicleLicenseNumber
     * @param beginDate 开始日期
     * @param endDate 结束日期
     * @return 运单信息集合
     */
    @Override
    public List<TWayBillInfo> selectTWayBillInfoUsedByProfitStatistic(String vehicleLicenseNumber, Date beginDate, Date endDate)
    {
        return tWayBillInfoMapper.selectTWayBillInfoUsedByProfitStatistic(vehicleLicenseNumber, beginDate, endDate);
    }

    /**
     * 查询运单信息列表，月利润单统计
     *
     * @param profitBillId 利润单ID
     * @param tWayBillInfo 运单信息
     * @return 运单信息集合
     */
    @Override
    public List<TWayBillInfo> selectTWayBillInfoByMonthProfitBillId(Long profitBillId, TWayBillInfo tWayBillInfo)
    {
        return tWayBillInfoMapper.selectTWayBillInfoByMonthProfitBillId(profitBillId, tWayBillInfo);
    }

    /**
     * 批量签收运单
     *
     * @param wayBillIds 需要签收的运单信息主键集合
     * @param tWayBillInfo 运单信息
     * @return 结果
     */
    @Override
    public int updateTWayBillInfoSignRelFieldsByWaybillIds(Long[] wayBillIds, TWayBillInfo tWayBillInfo)
    {
        return tWayBillInfoMapper.updateTWayBillInfoSignRelFieldsByWaybillIds(wayBillIds, tWayBillInfo);
    }

    /**
     * 查询运单信息列表
     *
     * @param wayBillIds 需要查询的运单信息主键集合
     * @return 运单信息集合
     */
    @Override
    public List<TWayBillInfo> selectTWayBillInfoListByWayBillIds(Long[] wayBillIds)
    {
        return tWayBillInfoMapper.selectTWayBillInfoListByWayBillIds(wayBillIds);
    }

    /**
     * 查询计划单号
     *
     * @param wayBillIds 需要查询的运单信息主键集合
     * @return 计划单号集合
     */
    @Override
    public List<String> selectTransportPlanNumberByWayBillIds(Long[] wayBillIds)
    {
        return tWayBillInfoMapper.selectTransportPlanNumberByWayBillIds(wayBillIds);
    }

    /**
     * 查询运单信息列表,查询，去程，回程运单，一对
     *
     * @param tWayBillInfo 运单信息
     * @return 运单信息集合
     */
    @Override
    public List<TWayBillInfo> selectTWayBillInfoListExt(TWayBillInfo tWayBillInfo)
    {
        return tWayBillInfoMapper.selectTWayBillInfoListExt(tWayBillInfo);
    }

    /**
     * 计算运单个数
     *
     * @param waybillNumber 运单信息主键
     * @return 运单信息
     */
    @Override
    public int countTWayBillInfoByWayBillNumber(String waybillNumber)
    {
        return tWayBillInfoMapper.countTWayBillInfoByWayBillNumber(waybillNumber);
    }

    /**
     * 删除运单信息信息
     *
     * @param waybillNumber 运单信息主键
     * @return 结果
     */
    @Override
    public int deleteTWayBillInfoByWayBillNumber(String waybillNumber)
    {
        return tWayBillInfoMapper.deleteTWayBillInfoByWayBillNumber(waybillNumber);
    }

    /**
     * 校验运单编号是否唯一
     *
     * @param tWayBillInfo 运单信息
     * @return 结果
     */
    @Override
    public String checkWayBillNumberUnique(TWayBillInfo tWayBillInfo)
    {
        Long wayBillId = StringUtils.isNull(tWayBillInfo.getWayBillId()) ? -1L : tWayBillInfo.getWayBillId();
        TWayBillInfo info = tWayBillInfoMapper.checkWayBillNumberUnique(tWayBillInfo.getWayBillNumber());
        if (StringUtils.isNotNull(info) && info.getWayBillId().longValue() != wayBillId.longValue())
        {
            return WaybillConstants.NOT_UNIQUE;
        }
        return WaybillConstants.UNIQUE;
    }

    /**
     * 司机姓名列表
     *
     * @param vehicleMark 车辆标记
     * @param beginDate 开始日期
     * @param endDate 结束日期
     * @return 结果
     */
    @Override
    public List<String> selectSalaryStatisticFieldByRecordDate(String vehicleMark, Date beginDate, Date endDate)
    {
        return tWayBillInfoMapper.selectSalaryStatisticFieldByRecordDate(vehicleMark, beginDate, endDate);
    }

    /**
     * 查询运单信息列表
     *
     * @param driverName 司机姓名
     * @param beginDate 开始日期
     * @param endDate 结束日期
     * @return 运单信息集合
     */
    @Override
    public List<TWayBillInfo> selectTWayBillInfoUsedBySalaryStatistic(String driverName, Date beginDate, Date endDate)
    {
        return tWayBillInfoMapper.selectTWayBillInfoUsedBySalaryStatistic(driverName, beginDate, endDate);
    }


    /**
     * 查询运单信息列表，月工资单统计
     *
     * @param salaryBillId 利润单ID
     * @param tWayBillInfo 运单信息
     * @return 运单信息集合
     */
    @Override
    public List<TWayBillInfo> selectTWayBillInfoByMonthSalaryBillId(Long salaryBillId, TWayBillInfo tWayBillInfo)
    {
        return tWayBillInfoMapper.selectTWayBillInfoByMonthSalaryBillId(salaryBillId, tWayBillInfo);
    }
}
